package com.coment.po.roles;

import com.coment.message.BuffInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Setter;
import org.springframework.data.annotation.Transient;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/// 战斗面板
@Setter
public class FightPanel {
    /// 战斗
    public volatile Map<Integer, Double> fight;

    /// buff属性 k:过期时间 v:属性
    public volatile List<BuffInfo> buff;

    @JsonIgnore
    @Transient
    public Map<Integer, Double> getValue() {
        Map<Integer, Double> result = new HashMap<>();
        this.fight.forEach((key, value) -> result.merge(key, value, Double::sum));


        for (BuffInfo buff1 : buff) {
            if (!buff1.isExpired()) {
                buff1.addValue.forEach((key, value) -> result.merge(key, value, Double::sum));
            }
        }

        return result;
    }

    public FightPanel() {
        fight = new HashMap<>();
        buff = new ArrayList<>();
    }

    public void clear() {
        buff.removeIf(BuffInfo::isExpired);
    }
}
